home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’93 / Inside Mac Movie Toolbox Code / mtb15.c < prev    next >
Encoding:
Text File  |  1992-10-22  |  2.0 KB  |  87 lines  |  [TEXT/KAHL]

  1. //    Copyright:    © 1992 by Apple Computer, Inc., all rights reserved.
  2.  
  3. #include "mtb.h"
  4.  
  5. void CreateTrackMatte (Track theTrack)
  6. {
  7.     QDErr err;
  8.     GWorldPtr aGW;
  9.     Rect trackBox;
  10.     Fixed trackHeight;
  11.     Fixed trackWidth;
  12.     CTabHandle grayCTab;
  13.  
  14.     GetTrackDimensions (theTrack, &trackWidth, &trackHeight);
  15.     SetRect (&trackBox, 0, 0, FixRound (trackWidth),
  16.                  FixRound (trackHeight));
  17.  
  18.     grayCTab = GetCTable(40);            // 8 bit + 32 = 8 bit gray 
  19.     err = NewGWorld (&aGW, 8, &trackBox, grayCTab,
  20.                          (GDHandle) nil, 0);
  21.     DisposeCTable (grayCTab);
  22.     if (!err && (aGW != nil)) {
  23.         SetTrackMatte (theTrack, aGW->portPixMap);
  24.         DisposeGWorld (aGW);
  25.     }
  26. }
  27.  
  28. void UpdateTrackMatte (Track theTrack)
  29. {
  30.     OSErr err;
  31.     PixMapHandle trackMatte;
  32.     PixMapHandle savePortPix;
  33.     Movie             theMovie;
  34.     GWorldPtr tempGW;
  35.     CGrafPtr savePort;
  36.     GDHandle saveGDevice;
  37.     Rect             matteBox;
  38.     short             i;
  39.  
  40.     theMovie = GetTrackMovie (theTrack);
  41.     trackMatte = GetTrackMatte (theTrack);
  42.     if (trackMatte == nil) {
  43.         // track doesn't have a matte, so give it one
  44.         CreateTrackMatte (theTrack);
  45.         trackMatte = GetTrackMatte (theTrack);
  46.         if (trackMatte == nil)
  47.             return;
  48.     }
  49.  
  50.     GetGWorld (&savePort, &saveGDevice);
  51.     matteBox = (**trackMatte).bounds;
  52.     err = NewGWorld(&tempGW, 
  53.                             (**trackMatte).pixelSize, &matteBox,
  54.                             (**trackMatte).pmTable, (GDHandle) nil, 0);
  55.     if (err || (tempGW == nil)) return;
  56.     
  57.     SetGWorld (tempGW, nil);
  58.     savePortPix = tempGW->portPixMap;
  59.     LockPixels (trackMatte);
  60.     SetPortPix (trackMatte);
  61.  
  62.     // draw a gray ramp rectangle around the edge of the matte     
  63.     for (i = 0; i < 35; i++)  {
  64.         RGBColor         aColor;
  65.         long             tempLong;
  66.  
  67.         tempLong = 65536 - ((65536 / 35) * (long)i);
  68.         aColor.red = aColor.green = aColor.blue = tempLong;
  69.         RGBForeColor(&aColor);
  70.         FrameRect (&matteBox);
  71.         InsetRect (&matteBox, 1, 1);
  72.     }
  73.     
  74.     // fill the center of the matte with black
  75.     ForeColor (blackColor);
  76.     PaintRect (&matteBox);
  77.     
  78.     SetPortPix (savePortPix);
  79.     SetGWorld (savePort, saveGDevice);
  80.     DisposeGWorld (tempGW);
  81.  
  82.     UnlockPixels (trackMatte);
  83.     SetTrackMatte (theTrack, trackMatte);
  84.  
  85.     DisposeMatte (trackMatte);
  86. }
  87.